package com.xl.baseMethod;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.LockSupport;

import static java.lang.Thread.sleep;

/**
 * JdkVersion: 1.8
 * Author: lei·xie
 * Created: 2024/8/5 0002 10:22
 * Description: 基本方法 线程状态
 */
@Slf4j(topic = "b.Test13")
public class ThreadDemo13 {
    public static void main(String[] args) throws InterruptedException{
        Thread t1 = new Thread(() -> {
            while (true) {
                log.debug("running..");
            }
        },"t1");
        Thread t2 = new Thread("t2") {
            @Override
            public void run() {
                while (true) { }
            }
        };
        t2.start();
        Thread t3 = new Thread(() -> {
            log.debug("running..");
        },"t3");
        t3.start();
        Thread t4 = new Thread(() -> {
            synchronized (ThreadDemo13.class) {
                try {
                    Thread.sleep(10000000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        },"t4");
        t4.start();
        Thread t5 = new Thread(() -> {
            try {
                t2.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        },"t5");
        t5.start();
        Thread t6 = new Thread(() -> {
            synchronized (ThreadDemo13.class) {
                try {
                    Thread.sleep(10000000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        },"t6");
        t6.start();

        Thread.sleep(500);
        log.debug("t1 state {}",t1.getState());
        log.debug("t2 state {}",t2.getState());
        log.debug("t3 state {}",t3.getState());
        log.debug("t4 state {}",t4.getState());
        log.debug("t5 state {}",t5.getState());
        log.debug("t6 state {}",t6.getState());
    }
}
